package com.atguigu.juc.study.chapter04.locks;

/**
 * @author : leimingchao
 * @date Date : 2022年06月12日 14:25
 */
public class ReEntryLockDemo {


    public synchronized void m1() {

        System.out.println(Thread.currentThread().getName() + "\t ---come in");

        m2();

        System.out.println(Thread.currentThread().getName() + "\t ---end m1");

    }

    public synchronized void m2() {

        System.out.println(Thread.currentThread().getName() + "\t ---come in");

        m3();

        System.out.println(Thread.currentThread().getName() + "\t ---end m2");
    }

    public synchronized void m3() {

        System.out.println(Thread.currentThread().getName() + "\t ---come in");
    }

    public static void main(String[] args) {

        //reEntryM1();

        ReEntryLockDemo reEntryLockDemo = new ReEntryLockDemo();

        new Thread(() -> {
            reEntryLockDemo.m1();
        }, "t1").start();
    }

    private static void reEntryM1() {
        final Object object = new Object();
        new Thread(() -> {
            synchronized (object) {
                System.out.println(Thread.currentThread().getName() + "\t 外层调用");
                synchronized (object) {
                    System.out.println(Thread.currentThread().getName() + "\t 中层调用");

                    synchronized (object) {
                        System.out.println(Thread.currentThread().getName() + "\t 内层调用");
                    }
                }
            }
        }, "t1").start();
    }
}
